package com.example.activitystudy;

import androidx.appcompat.app.AppCompatActivity;

import android.content.Intent;
import android.content.IntentFilter;
import android.os.Bundle;
import android.view.View;

public class ReceiverActivity extends AppCompatActivity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_receiver);

        //2.初始化动态广播接收者
        ProxyReceiver proxyReceiver=new ProxyReceiver();
        IntentFilter filter=new IntentFilter();
        filter.addAction(ActionUtils.ACTION_EQUES_UPDATE_IP);
        registerReceiver(proxyReceiver,filter);
    }

    //静态发送广播
    public void sendAction1(View view) {
    //发送给接收者
        Intent intent=new Intent();
        intent.setPackage("com.example.activitystudy");
        intent.setAction(ActionUtils.ACTION_FLAG);
        sendBroadcast(intent);
    }

    //动态发送广播
    //动态注册的接收者
    public void sendAction2(View view) {

        Intent intent =new Intent();
        intent.setPackage("com.example.activitystudy");
        intent.setAction(ActionUtils.ACTION_EQUES_UPDATE_IP);
        sendBroadcast(intent);
    }
}